package cn.gson.crm.controller;

import cn.gson.crm.model.pojos.Employee;
import cn.gson.crm.model.pojos.SalesAt;
import cn.gson.crm.model.service.SalesAtService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/shou")
public class SalesAtController {
    @Autowired
    SalesAtService salesAtService;

    @RequestMapping("/selectSalestAt")
    @ResponseBody
    //分页查询
    public Map<String ,Object> select1(Integer currentPage, Integer PageSize,String salesAttime){
        Page<Object> obj= PageHelper.startPage(currentPage,PageSize);
        salesAtService.selectSalesAt(salesAttime);
        Map<String,Object> map=new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("row",obj.getResult());
        return map;
    }
    @RequestMapping("/sellSalesAt")
    @ResponseBody
    //年份查询
    public Map<String,Object> selectSalesAt(String salesAttime){
        Map<String,Object> map=null;
        map=salesAtService.selectSalesAt(salesAttime);
        return map;
    }
    @RequestMapping("/sellSalesAt2")
    @ResponseBody
    //月份查询
    public Map<String,Object> selectSalesAt2(String salesAttime){
        Map<String,Object> map=null;
        map=salesAtService.selectSalesAt2(salesAttime);
        return map;
    }
    @RequestMapping("/sellSalesAt3")
    @ResponseBody
    //日期查询
    public Map<String,Object> selectSalesAt3(String salesAttime){
        Map<String,Object> map=null;
        map=salesAtService.selectSalesAt3(salesAttime);
        return map;
    }
    //目标新增
    @RequestMapping("/addsalest")
    @ResponseBody
    public void addsalest(@RequestBody SalesAt salesAt){
        System.out.println(salesAt);
        salesAtService.addsalesAt(salesAt);
    }
    //查询员工表格
    @RequestMapping("/selectEmployee")
    @ResponseBody
    public List<Employee> selectEmployee(){
        return salesAtService.employeeList();
    }

    //主页查询销售目标
    @RequestMapping("/selectvalue2")
    @ResponseBody
    public Map<String,Object> selectvalue2(String orderTime){
        System.out.println("。。。"+orderTime);
        Map<String,Object> map=null;
        if(orderTime.equals("2020")){
            map =salesAtService.selectvalue2();
        }
        if(orderTime.equals("2019")){
            map= salesAtService.selectvalue3();
        }
        if(orderTime.equals("6")){
            map= salesAtService.selectvalue4();
        }
        if(orderTime.equals("16")){
            map=salesAtService.selectvalue5();
        }
     return map;
    }
}
